import { reactive, toRefs } from 'vue'
import { createModelOrFolder, getModeDir, modifyModelOrFolder, removeModel } from '@/api/cube/index'
import { MessageBox, Message } from 'bin-ui-next'
import { throwError } from '@/utils/util'

const defaultValue = {
  id: 0,
  name: '全部分组',
  directory: 'Y',
}

export default function useModelFolder() {
  const folderData = reactive({
    selectedPid: defaultValue.id, // 选中的内容
    selectedName: defaultValue.name, // 选中的分组名称
    folderList: [],
    adding: false,
  })

  const toggleProject = ({ id, name }) => {
    folderData.selectedPid = id
    folderData.selectedName = name
  }

  // 获取数据集分组列表
  const getFolders = () => {
    getModeDir().then(res => {
      if (res && res.length > 1) {
        folderData.folderList = res
      } else {
        folderData.folderList = []
      }
    })
  }

  getFolders()

  return {
    ...toRefs(folderData),
    toggleProject
  }
}
